package com.cloud.sentinel.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RefreshScope
public class TestController {

    @GetMapping(value = "/testA")
    public String getTestA(){
        System.out.println(Thread.currentThread().getName()+"\t"+"........textA");
        return "************TestA";
    }

    @GetMapping(value = "/testB")
    public String getTestB(){
        System.out.println(Thread.currentThread().getName()+"\t"+"........textA");
        return "************TestB";
    }

    // 热点
    @GetMapping(value = "/hotkey")
    @SentinelResource(value = "hotkey",blockHandler = "hotkey_Fallback")
    public String getHotKey(@RequestParam(value = "p1",required = false) String p1,
                            @RequestParam(value = "p2",required = false) String p2){
        return "************hotkey";
    }

    public String hotkey_Fallback(String p1, String p2, BlockException exception){
        return "************hotkey_Fallback,o(╥﹏╥)o";
    }



}
